<template>
  <div id="loading" v-show="loadingState">
    <div class="particles-container">
      <div class="particle" v-for="i in 20" :key="i"></div>
    </div>
    <div class="fanfan-loading">
      <h1>
        <span>f</span>
        <span>a</span>
        <span>n</span>
        <span>f</span>
        <span>a</span>
        <span>n</span>
      </h1>
    </div>
    <div class="fireworks-container">
      <div class="firework" v-for="i in 12" :key="i" :style="{ 
        left: Math.random() * 100 + '%', 
        top: Math.random() * 100 + '%',
        animationDelay: Math.random() * 2 + 's'
      }"></div>
    </div>
  </div>
</template>

<script setup>
import {computed} from 'vue'
import {useLoadingStore} from "../../stores/loading";

const loadingStore = useLoadingStore()
const loadingState = computed(() => {
  return loadingStore.loading
});

// 不需要额外的JavaScript，CSS动画会自动运行
</script>

<style scoped lang="scss">
#loading {
  position: fixed;
  z-index: 99999;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #28212e 0%, #1a1a2e 50%, #16213e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.particles-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: float 8s infinite linear;
}

.particle:nth-child(1) { left: 10%; animation-delay: 0s; }
.particle:nth-child(2) { left: 20%; animation-delay: 1s; }
.particle:nth-child(3) { left: 30%; animation-delay: 2s; }
.particle:nth-child(4) { left: 40%; animation-delay: 3s; }
.particle:nth-child(5) { left: 50%; animation-delay: 4s; }
.particle:nth-child(6) { left: 60%; animation-delay: 5s; }
.particle:nth-child(7) { left: 70%; animation-delay: 6s; }
.particle:nth-child(8) { left: 80%; animation-delay: 7s; }
.particle:nth-child(9) { left: 90%; animation-delay: 0.5s; }
.particle:nth-child(10) { left: 15%; animation-delay: 1.5s; }
.particle:nth-child(11) { left: 25%; animation-delay: 2.5s; }
.particle:nth-child(12) { left: 35%; animation-delay: 3.5s; }
.particle:nth-child(13) { left: 45%; animation-delay: 4.5s; }
.particle:nth-child(14) { left: 55%; animation-delay: 5.5s; }
.particle:nth-child(15) { left: 65%; animation-delay: 6.5s; }
.particle:nth-child(16) { left: 75%; animation-delay: 7.5s; }
.particle:nth-child(17) { left: 85%; animation-delay: 1.2s; }
.particle:nth-child(18) { left: 95%; animation-delay: 2.2s; }
.particle:nth-child(19) { left: 5%; animation-delay: 3.2s; }
.particle:nth-child(20) { left: 25%; animation-delay: 4.2s; }

@keyframes float {
  0% {
    transform: translateY(100vh) scale(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
    transform: scale(1);
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-100vh) scale(0);
    opacity: 0;
  }
}

.fanfan-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 10;
  text-align: center;
  margin: 0 auto;
  padding: 0;
}

.fanfan-loading h1 {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
  left: 0;
  top: 0;
  transform: none;
}

.fanfan-loading span {
  position: relative;
  font-family: 'Lato', sans-serif;
  color: white;
  font-size: 5rem;
  text-shadow: 0 1px 0 #b7b7b7, 0 2px 0 #b7b7b7, 0 3px 0 #b7b7b7, 0 4px 0 #b7b7b7, 0 5px 0 #b7b7b7, 0 6px 0 transparent, 0 7px 0 transparent, 0 8px 0 transparent, 0 9px 0 transparent, 0 10px 10px rgba(0,0,0,0.5);
  animation: bounce 0.4s ease infinite alternate;
  display: inline-block;
  transform: translateY(0);
  margin: 0;
  padding: 0;
  vertical-align: baseline;
}

/* 每个字母的动画延迟 */
.fanfan-loading span:nth-child(2) {
  animation-delay: 0.1s;
}
.fanfan-loading span:nth-child(3) {
  animation-delay: 0.2s;
}
.fanfan-loading span:nth-child(4) {
  animation-delay: 0.3s;
}
.fanfan-loading span:nth-child(5) {
  animation-delay: 0.4s;
}
.fanfan-loading span:nth-child(6) {
  animation-delay: 0.5s;
}

@keyframes bounce {
  100% {
    transform: translateY(-20px);
    text-shadow: 0 1px 0 #ccc, 0 2px 0 #ccc, 0 3px 0 #ccc, 0 4px 0 #ccc, 0 5px 0 #ccc, 0 6px 0 #ccc, 0 7px 0 #ccc, 0 8px 0 #ccc, 0 9px 0 #ccc, 0 60px 30px rgba(0,0,0,0.3);
  }
}

/* 烟花容器 */
.fireworks-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* 烟花效果 */
.firework {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  animation: firework 1.5s ease-out infinite;
}

.firework:nth-child(1) { background: #ff6b6b; }
.firework:nth-child(2) { background: #4ecdc4; }
.firework:nth-child(3) { background: #45b7d1; }
.firework:nth-child(4) { background: #f9ca24; }
.firework:nth-child(5) { background: #f0932b; }
.firework:nth-child(6) { background: #eb4d4b; }
.firework:nth-child(7) { background: #6ab04c; }
.firework:nth-child(8) { background: #c44569; }
.firework:nth-child(9) { background: #f8b500; }
.firework:nth-child(10) { background: #a29bfe; }
.firework:nth-child(11) { background: #fd79a8; }
.firework:nth-child(12) { background: #00b894; }

@keyframes firework {
  0% {
    transform: scale(0) translateY(0);
    opacity: 1;
  }
  10% {
    transform: scale(1) translateY(-20px);
    opacity: 1;
  }
  100% {
    transform: scale(0) translateY(-200px);
    opacity: 0;
  }
}

/* 添加闪烁的星星背景 */
#loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(2px 2px at 20px 30px, #eee, transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 90px 40px, #fff, transparent),
    radial-gradient(1px 1px at 130px 80px, rgba(255,255,255,0.6), transparent),
    radial-gradient(2px 2px at 160px 30px, #ddd, transparent);
  background-repeat: repeat;
  background-size: 200px 100px;
  animation: sparkle 3s linear infinite;
  z-index: 0;
}

@keyframes sparkle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
/* 粒子飘散效果 */
.particles-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: float 8s infinite linear;
}

.particle:nth-child(1) { left: 10%; animation-delay: 0s; }
.particle:nth-child(2) { left: 20%; animation-delay: 1s; }
.particle:nth-child(3) { left: 30%; animation-delay: 2s; }
.particle:nth-child(4) { left: 40%; animation-delay: 3s; }
.particle:nth-child(5) { left: 50%; animation-delay: 4s; }
.particle:nth-child(6) { left: 60%; animation-delay: 5s; }
.particle:nth-child(7) { left: 70%; animation-delay: 6s; }
.particle:nth-child(8) { left: 80%; animation-delay: 7s; }
.particle:nth-child(9) { left: 90%; animation-delay: 0.5s; }
.particle:nth-child(10) { left: 15%; animation-delay: 1.5s; }
.particle:nth-child(11) { left: 25%; animation-delay: 2.5s; }
.particle:nth-child(12) { left: 35%; animation-delay: 3.5s; }
.particle:nth-child(13) { left: 45%; animation-delay: 4.5s; }
.particle:nth-child(14) { left: 55%; animation-delay: 5.5s; }
.particle:nth-child(15) { left: 65%; animation-delay: 6.5s; }
.particle:nth-child(16) { left: 75%; animation-delay: 7.5s; }
.particle:nth-child(17) { left: 85%; animation-delay: 1.2s; }
.particle:nth-child(18) { left: 95%; animation-delay: 2.2s; }
.particle:nth-child(19) { left: 5%; animation-delay: 3.2s; }
.particle:nth-child(20) { left: 25%; animation-delay: 4.2s; }

@keyframes float {
  0% {
    transform: translateY(100vh) scale(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
    transform: scale(1);
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-100vh) scale(0);
    opacity: 0;
  }
}

/* 添加光晕效果 */
.fanfan-loading h1 {
  position: relative;
  filter: drop-shadow(0 0 20px rgba(168, 85, 247, 0.5));
}

.fanfan-loading h1::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.3) 0%, transparent 70%);
  transform: translate(-50%, -50%);
  animation: pulse 2s ease-in-out infinite;
  z-index: -1;
}

@keyframes pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0.8;
  }
}

/* 添加彩虹渐变边框 */
#loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 2px solid transparent;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #f9ca24, #f0932b, #eb4d4b, #6ab04c) border-box;
  border-radius: 20px;
  animation: rainbow-border 3s linear infinite;
  z-index: -1;
  opacity: 0.3;
}

@keyframes rainbow-border {
  0% {
    filter: hue-rotate(0deg);
  }
  100% {
    filter: hue-rotate(360deg);
  }
}

/* 移动端适配 */
@media (max-width: 768px) {
  #loading {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
  }
  
  .fanfan-loading span {
    font-size: 3.5rem;
  }
  
  @keyframes bounce {
    100% {
      transform: translateY(-15px);
      text-shadow: 0 1px 0 #ccc, 0 2px 0 #ccc, 0 3px 0 #ccc, 0 4px 0 #ccc, 0 5px 0 #ccc, 0 6px 0 #ccc, 0 7px 0 #ccc, 0 8px 0 #ccc, 0 9px 0 #ccc, 0 40px 20px rgba(0,0,0,0.3);
    }
  }
}
</style>
